<?php
namespace app\common\model;
use think\Model;

/**
 * @author: jim
 * @date: 2017/11/16
 */
class LogModel extends Model
{
    protected $connection = 'JS_SERVE';
    protected $table = 'log';
    protected $resultSetType = 'collection';

    public function add($level = "error",$message = "出错啦",$context = "") {
        $this->data([
            'level'  =>  $level,
            'message' =>  $message,
            'context' => json_encode($context),
            'ip' => getIp(),
            'url' => getUrl(),
            'create_on' => date('Y-m-d H:i:s',time())

        ]);
        $this->save();
        return $this->id;
    }
}